<?php

namespace app\admin\command;


use think\Cache;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\Db;
use think\Exception;


class Area extends Command
{

    protected function configure()
    {
        $this
            ->setName('area')
            ->setDescription('将area信息写入Redis');
    }

    /**
     * 命令行安装
     */
    protected function execute(Input $input, Output $output)
    {
        $namearr = [1 => 'geo:province', 2 => 'geo:city', 3 => 'geo:district'];
		$areaData=Db::name('area')->select();
		$redis = Cache::store('redis')->handler();
		foreach($areaData as $key=>$value){
			$geoname = $namearr[$value['level']];
			$redis->geoadd($geoname,$value['lng'],$value['lat'],$value['id']);
		}
        $output->info("Write In Successed!");
    }
}
